BTC_intro =
{
	disableSerialization;
	_cam = "camera" camCreate [(position BTC_flag select 0) - 120, (position BTC_flag select 1) + 100, 40];
	_cam camSetTarget player;
	_cam cameraEffect ["internal", "BACK"];
	_cam camSetPos [(position BTC_flag select 0) + 120, (position BTC_flag select 1) + 100, 40];
	_cam camCommit 25;
	sleep 10;
	titleRsc ["BTC_intro", "PLAIN"];
	[format ["%1.%2.%3  %4:%5", (date) select 0,(date) select 1,(date) select 2,(date) select 3,(date) select 4]] spawn BIS_fnc_infoText;
	sleep 7;
	[format ["Welcome to %1", worldName] , format ["%1", name player]] spawn BIS_fnc_infoText;
	sleep 7;
	[str("War Storm"), str("by Giallustio")] spawn BIS_fnc_infoText;
	WaitUntil {camcommitted _cam};
	_cam camSetPos [position player select 0, position player select 1, 2.2];
	_cam camCommit 3;
	WaitUntil {camcommitted _cam};
	player cameraEffect ["terminate","back"];
	camDestroy _cam;
	titleText ["", "PLAIN"];
	[str ("Have a good game")] spawn BIS_fnc_infoText;
};
BTC_outro =
{
	/*
	BTC_return_task = player createSimpleTask ["Return To Base"];
	BTC_return_task setSimpleTaskDescription ["Return To Base.","Return To Base","Return To Base"];
	[] spawn {sleep 5;taskhint ["New Task!\nReturn to Base!", [1, 1, 1, 1], "taskNew"];};
	BTC_outro_start = false;
	while {!BTC_outro_start} do
	{
		_west = [];
		{if (side _x == west) then {_west = _west + [_x];};} foreach allUnits;
		if (({_x distance BTC_flag < 250} count _west) == (count _west)) then {BTC_outro_start = true;publicVariable "BTC_outro_start";};
		sleep 1;
	};
	BTC_return_task setTaskState "SUCCEEDED";
	*/
	hint format ["Good job %1!\nEnemy army has been defeated!", name player];
	sleep 10;
	titleText ["", "BLACK OUT"];
	sleep 2;
	titleText ["", "BLACK FADED"];
	sleep 1;
	titleText ["", "BLACK IN"];
	cutRsc ["BTC_intro", "PLAIN"];
	private ["_cam"];
	_cam = "camera" camCreate [position player select 0,position player select 1,2];
	_cam camSetTarget player;
	_cam cameraEffect ["internal", "BACK"];
	_cam camCommit 0;
	_cam camSetPos [position player select 0, (position player select 1) - 40, 20];
	_cam camCommit 20;
	sleep 1;
	titleText ["Enemy army has been defeated! \n THE WAR IS OVER!!!", "PLAIN"];
	BTC_end = true;
	publicvariable "BTC_end";
	sleep 10;
	forceEnd;
	sleep 2;
	player cameraEffect ["terminate","back"];
	camDestroy _cam;
};
BTC_m_actions_resp =
{
	WaitUntil {sleep 1; Alive player};
	player addAction [("<t color=""#12F905"">") + ("Set FOB") + "</t>","=BTC=_revive\=BTC=_addAction.sqf",[[],BTC_set_fob], 8, true, true, "", "count (nearestObjects [position player, BTC_fob_materials, 4]) > 0"];
	if (rank player == "CAPTAIN") then 
	{
		player addAction [("<t color=""#ffcc00"">") + ("Request side mission") + "</t>","=BTC=_revive\=BTC=_addAction.sqf",[[],{BTC_to_server = [1];publicVariableServer "BTC_to_server";}], -8, false, true, "", "!BTC_sm_assigned"];
		player addAction [("<t color=""#ED2744"">") + ("Abort side mission") + "</t>","=BTC=_revive\=BTC=_addAction.sqf",[[],{BTC_to_server = [2];publicVariableServer "BTC_to_server";}], -8, false, true, "", "BTC_sm_assigned"];
		player addaction [("<t color=""#27EE1F"">") + ("Rally point") + "</t>","=BTC=_revive\=BTC=_addAction.sqf",[[],BTC_action_rally_point],-8,false,false,"","isNil ""BTC_rally_point_deployed"""];
	};
};
BTC_set_fob =
{
	_cond = false;
	_array = nearestObjects [position player, BTC_fob_materials, 10];
	if (count _array > 0) then {_cond = true;};
	if (!_cond) exitWith {hint "Can't find the material required!";};
	_cond = false;
	_obj = _array select 0;
	if (_obj distance getMarkerpos "respawn_west" > 500) then {_cond = true;};//500
	if (!_cond) exitWith {hint "Too close to the main base!";};
	_pos = getPos _obj;
	deleteVehicle _obj;
	hint "Get back! Mounting FOB";
	_struc = createVehicle [BTC_fob_sign, [_pos select 0,_pos select 1,-10], [], 0, "NONE"];//"Land_Cargo_HQ_V1_F" // "Land_Cargo_House_V1_F"
	_flag  = createVehicle ["FlagPole_F", _pos, [], 0, "NONE"];
	_h = - 10;
	while {_h < 0} do
	{
		_h = _h + 0.1;
		_struc setpos [_pos select 0,_pos select 1,_h];
		sleep 0.1;
	};
	{_x setpos _pos} foreach [_flag,_struc];
	_flag setVariable ["BTC_mobile_west",format ["FOB_%1",BTC_fob_id],true];
	BTC_vehs_mobile_west_str = BTC_vehs_mobile_west_str + [format ["FOB_%1",BTC_fob_id]];
	BTC_fob_id = BTC_fob_id + 1;publicVariable "BTC_fob_id";publicVariable "BTC_vehs_mobile_west_str";
	_flag setvariable ["BTC_cannot_lift",1,true];
	_flag setVariable ["BTC_cannot_drag",1,true];
	_flag setVariable ["BTC_cannot_load",1,true];
	_flag setVariable ["BTC_cannot_place",1,true];
	_marker = createmarkerLocal [(_flag getVariable "BTC_mobile_west"), getPos _flag];
	(_flag getVariable "BTC_mobile_west") setMarkerSizeLocal [0.5,0.5];
	(_flag getVariable "BTC_mobile_west") setMarkerTypeLocal "hd_flag";
	(_flag getVariable "BTC_mobile_west") setMarkerTextLocal (_flag getVariable "BTC_mobile_west");
	(_flag getVariable "BTC_mobile_west") setMarkerColorLocal "ColorBlue";
	(_flag getVariable "BTC_mobile_west") setMarkerShapelocal "ICON";	
	BTC_m_PVEH = [1,_flag];publicVariable "BTC_m_PVEH";
	_flag addAction [("<t color=""#12F905"">") + ("Dismantle FOB") + "</t>","=BTC=_revive\=BTC=_addAction.sqf",[[_flag],BTC_dismantle_fob], 8, true, true, "", "true"];
	hint "FOB assembled!";
};
BTC_dismantle_fob =
{
	_obj = _this select 0;
	_obj lock true;
	_var = _obj getVariable "BTC_mobile_west";
	deleteMarkerLocal _var;
	BTC_vehs_mobile_west_str = BTC_vehs_mobile_west_str - [_var];publicVariable "BTC_vehs_mobile_west_str";
	BTC_m_PVEH = [2,_obj];publicVariable "BTC_m_PVEH";
	_s = nearestObject [_obj, BTC_fob_sign];
	sleep 1;
	deleteVehicle _s;
	deleteVehicle _obj;
};
X_fnc_returnConfigEntry = 
{
	/*
		File: returnConfigEntry.sqf
		Author: Joris-Jan van 't Land

		Description:
		Explores parent classes in the run-time config for the value of a config entry.
		
		Parameter(s):
		_this select 0: starting config class (Config)
		_this select 1: queried entry name (String)
		
		Returns:
		Number / String - value of the found entry
	*/
	if ((count _this) < 2) exitWith {nil};
	private ["_config", "_entryName"];
	_config = _this select 0;
	_entryName = _this select 1;
	if ((typeName _config) != (typeName configFile)) exitWith {nil};
	if ((typeName _entryName) != (typeName "")) exitWith {nil};
	private ["_entry", "_value"];
	_entry = _config >> _entryName;
	if (((configName (_config >> _entryName)) == "") && (!((configName _config) in ["CfgVehicles", "CfgWeapons", ""]))) then {
		[inheritsFrom _config, _entryName] call X_fnc_returnConfigEntry;
	} else {
		if (isNumber _entry) then {
			_value = getNumber _entry;
		} else {
			if (isText _entry) then {_value = getText _entry};
		};
	};
	if (isNil "_value") exitWith {nil};
	_value
};
BTC_maintenance_veh =
{
	// by Xeno
	private ["_config","_count","_i","_magazines","_object","_type","_type_name"];

	_object = (nearestObjects [position player, ["LandVehicle","Air"], 10]) select 0;
	if (!Alive _object) exitWith {hint "The vehicle has been destroyed";};
	_type = typeof _object;
	hint format ["%1 under maintenance",typeof _object];
	_reload_time = 2;

	_object action ["engineOff", _object];
	if (!alive _object) exitWith {};
	_object setFuel 0;
	_object setVehicleAmmo 1;

	_magazines = getArray(configFile >> "CfgVehicles" >> _type >> "magazines");

	if (count _magazines > 0) then {
		_removed = [];
		{
			if (!(_x in _removed)) then {
				_object removeMagazines _x;
				_removed set [count _removed, _x];
			};
		} forEach _magazines;
		{
			sleep _reload_time;
			if (!alive _object) exitWith {};
			_object addMagazine _x;
		} forEach _magazines;
	};

	_turrets = [configFile >> "CfgVehicles" >> _type >> "Turrets"] call X_fnc_returnVehicleTurrets;

	_reloadTurrets = {
		private ["_turrets", "_path"];
		_turrets = _this select 0;
		_path = _this select 1;

		private ["_i"];
		_i = 0;
		while {_i < (count _turrets)} do {
			private ["_turretIndex", "_thisTurret"];
			_turretIndex = _turrets select _i;
			_thisTurret = _path + [_turretIndex];
			
			_magazines = _object magazinesTurret _thisTurret;
			if (!alive _object) exitWith {};
			_removed = [];
			{
				if (!(_x in _removed)) then {
					_object removeMagazinesTurret [_x, _thisTurret];
					_removed set [count _removed, _x];
				};
			} forEach _magazines;
			if (!alive _object) exitWith {};
			{
				sleep _reload_time;
				if (!alive _object) exitWith {};
				_object addMagazineTurret [_x, _thisTurret];
				sleep _reload_time;
				if (!alive _object) exitWith {};
			} forEach _magazines;
			
			if (!alive _object) exitWith {};
			
			[_turrets select (_i + 1), _thisTurret] call _reloadTurrets;
			_i = _i + 2;
			if (!alive _object) exitWith {};
		};
	};

	if (count _turrets > 0) then {
		[_turrets, []] call _reloadTurrets;
	};

	if (!alive _object) exitWith {};

	_object setVehicleAmmo 1;

	sleep _reload_time;
	if (!alive _object) exitWith {};
	_object setDamage 0;
	sleep _reload_time;
	if (!alive _object) exitWith {};
	while {fuel _object < 0.99} do {
		_object setFuel 1;
		sleep 0.01;
	};
	sleep _reload_time;
	if (!alive _object) exitWith {};

	reload _object;
	hint "Maintenance complete";
};
BTC_repair_wreck =
{
	_object = (nearestObjects [position player, ["LandVehicle","Air"], 10]) select 0;
	if (damage _object != 1) exitWith {hint "Use the maintenance action!"};
	BTC_to_server = [0,_object];publicVariableServer "BTC_to_server";
};
BTC_create_tag =
{
	private ["_name","_text","_cursor","_ui","_tag","_color","_veh","_driver","_gunner","_commander","_crew","_crew_name","_array","_name_driver","_name_gunner","_name_commander"];
	_name = "";
	_cursor = cursorTarget;
	_cond = false;
	if (!isNull _cursor && (player distance _cursor < BTC_range_name) && isPlayer _cursor) then {_cond = true;};
	if (_cond && (_cursor isKindOf "Air" || _cursor isKindOf "LandVehicle")) then {if (count (crew _cursor) > 0) then {_cond = true;} else {_cond = false;};};
	if (_cond) then 
	{
		disableserialization;
		cutRsc ["BTC_hud_name_tag", "PLAIN"];
		_name = name _cursor;
		_ui   = uiNamespace getVariable "BTC_TAG_HUD";
		_tag  = _ui displayCtrl 1201;
		if (_cursor isKindOf "Man") then
		{
			if (side player == side _cursor) then {_color = "#42FA05";} else {_color = "#FF0000";};
			_text = format ["<t color='%2'>%1</t>", _name, _color];
		}
		else
		{
			if (side player == side _cursor) then 
			{
				_veh = vehicle _cursor;
				_driver = driver _veh;
				_gunner = gunner _veh;
				_commander = commander _veh;
				_crew = crew _veh;_crew_name = "";_array = "";_name_driver = "";_name_gunner = "";_name_commander = "";
				if (!isNull _driver) then {_name_driver = format ["<img image='\A3\ui_f\data\IGUI\RscIngameUI\RscUnitInfo\role_driver_ca.paa'/>%1<br/>",name _driver];_crew = _crew - [_driver];};
				if (!isNull _gunner) then {_name_gunner = format ["<img image='\A3\ui_f\data\IGUI\RscIngameUI\RscUnitInfo\role_gunner_ca.paa'/>%1<br/>",name _gunner];_crew = _crew - [_gunner];};
				if (!isNull _commander) then {_name_commander = format ["<img image='\A3\ui_f\data\IGUI\RscIngameUI\RscUnitInfo\role_commander_ca.paa'/>%1<br/>",name _commander];_crew = _crew - [_commander];};
				if (count _crew > 0) then {{_crew_name = _crew_name + format ["<img image='\A3\ui_f\data\IGUI\RscIngameUI\RscUnitInfo\role_cargo_ca.paa'/>%1<br/>",name _x];} foreach _crew;};
				{if (_x != "") then {_array = _array + _x;};} foreach [_name_driver,_name_gunner,_name_commander,_crew_name];
				_text = format ["<t color='%1'>%2</t>", "#42FA05",_array];
			}
			else {_text = format ["<t color='%1'>%Occupied</t>", "#FF0000"];};
		};
		_tag ctrlSetStructuredText parseText _text;
	};
};
BTC_create_veh_info_hud =
{
	if (vehicle player != player) then 
	{
		private ["_text","_ui","_tag","_veh","_driver","_gunner","_commander","_crew","_crew_name","_array","_name_driver","_name_gunner","_name_commander"];
		disableserialization;
		cutRsc ["BTC_hud_name_tag", "PLAIN"];
		_ui   = uiNamespace getVariable "BTC_TAG_HUD";
		_tag  = _ui displayCtrl 1202;
		_veh = vehicle player;
		_driver = driver _veh;
		_gunner = gunner _veh;
		_commander = commander _veh;
		_crew = crew _veh;_crew_name = "";_array = "";_name_driver = "";_name_gunner = "";_name_commander = "";
		if (!isNull _driver) then {_name_driver = format ["<img image='\A3\ui_f\data\IGUI\RscIngameUI\RscUnitInfo\role_driver_ca.paa'/>%1<br/>",name _driver];_crew = _crew - [_driver];};
		if (!isNull _gunner) then {_name_gunner = format ["<img image='\A3\ui_f\data\IGUI\RscIngameUI\RscUnitInfo\role_gunner_ca.paa'/>%1<br/>",name _gunner];_crew = _crew - [_gunner];};
		if (!isNull _commander) then {_name_commander = format ["<img image='\A3\ui_f\data\IGUI\RscIngameUI\RscUnitInfo\role_commander_ca.paa'/>%1<br/>",name _commander];_crew = _crew - [_commander];};
		if (count _crew > 0) then {{_crew_name = _crew_name + format ["<img image='\A3\ui_f\data\IGUI\RscIngameUI\RscUnitInfo\role_cargo_ca.paa'/>%1<br/>",name _x];} foreach _crew;};
		{if (_x != "") then {_array = _array + _x;};} foreach [_name_driver,_name_gunner,_name_commander,_crew_name];
		_text = format ["<t color='%1'>%2</t>", "#42FA05",_array];
		_tag ctrlSetStructuredText parseText _text;
	};
};
BTC_m_fnc_PVEH =
{
	_array = _this select 1;
	_type  = _array select 0;
	switch (true) do
	{
		case (_type == 0) : 
		{
			private ["_city"];
			_city = _array select 1;
			format ["%1_marker", _city] setMarkerColorLocal "ColorGreen";
			["TaskSucceeded",["Task accomplished!","City has been secured!"]] call bis_fnc_showNotification;
		};
		case (_type == 1) : 
		{
			private ["_fob"];
			_fob = _array select 1;
			_fob addAction [("<t color=""#12F905"">") + ("Dismantle FOB") + "</t>","=BTC=_revive\=BTC=_addAction.sqf",[[_fob],BTC_dismantle_fob], 8, true, true, "", "true"];
			_marker = createmarkerLocal [(_flag getVariable "BTC_mobile_west"), getPos _flag];
			(_fob getVariable "BTC_mobile_west") setMarkerSizeLocal [0.5,0.5];
			(_fob getVariable "BTC_mobile_west") setMarkerTypeLocal "hd_flag";
			(_fob getVariable "BTC_mobile_west") setMarkerTextLocal (_fob getVariable "BTC_mobile_west");
			(_fob getVariable "BTC_mobile_west") setMarkerColorLocal "ColorBlue";
			(_fob getVariable "BTC_mobile_west") setMarkerShapelocal "ICON";	
		};
		case (_type == 2) : 
		{
			private ["_fob"];
			_fob = _array select 1;
			deleteMarkerLocal (_fob getVariable "BTC_mobile_west");
		};
		case (_type == 3) : 
		{
			private ["_fob"];
			_suit = _array select 1;
			_suit addAction [("<t color=""#12F905"">") + ("Get Intel") + "</t>","=BTC=_revive\=BTC=_addAction.sqf",[[_suit],{deleteVehicle (_this select 0);}], 8, true, true, "", "true"];
		};
		case (_type == 4) :
		{
			_outro = [] spawn BTC_outro;
		};
		case (_type == 5) :
		{
			private ["_text"];
			_text = _array select 1;
			hint _text;
		};
	};
};
BTC_sm_fnc_PVEH =
{
	_array = _this select 1;
	_array spawn
	{
		private ["_city"];
		_id  = _this select 0;
		_n   = _this select 1;
		_pos = _this select 2;
		
		_sm = BTC_side_missions select _n;
		
		_title = _sm select 0;
		_desc  = _sm select 1;
		_text  = _sm select 2;
		_marker = createmarkerLocal [format ["BTC_marker_sm_%1",_id], getpos _pos];
		format ["BTC_marker_sm_%1",_id] setMarkerSizeLocal [0.5,0.5];
		format ["BTC_marker_sm_%1",_id] setMarkerTypeLocal "mil_unknown";
		format ["BTC_marker_sm_%1",_id] setMarkerColorLocal "ColorRed";
		format ["BTC_marker_sm_%1",_id] setMarkerShapelocal "ICON";				
		
		_task = player createSimpleTask [_title];
		_task setSimpleTaskDescription [format [_desc,format ["BTC_marker_sm_%1",_id]],_title,""];
		_task setSimpleTaskDestination (getpos _pos);
		["TaskAssigned",["Side mission assigned!","Check your tasks for details!"]] call bis_fnc_showNotification; 
		waitUntil {sleep 5; (BTC_sm_status != "")};
		if (BTC_sm_status == "Y") then 
		{
			_task setTaskState "Succeeded";
			["TaskSucceeded",["Side mission accomplished!",_text]] call bis_fnc_showNotification;
		}
		else
		{
			_task setTaskState "Canceled";
			["TaskCanceled",["","Side mission aborted!"]] call bis_fnc_showNotification;
		};
	};
};
BTC_action_rally_point =
{
	if (isNil "BTC_rally_point_deployed") then
	{
		BTC_rally_point_deployed = true;publicVariable "BTC_rally_point_deployed";
		_pos = getPosATL player;
		BTC_rally_point setPos _pos;
		"BTC_rally_point" setMarkerPos _pos;
		"BTC_rally_point" setMarkerSize [0.5,0.5];
		"BTC_rally_point" setMarkerText "Rally Point";
	}
	else
	{
		BTC_rally_point setPos getMarkerPos "respawn_west";
		"BTC_rally_point" setMarkerSize [0,0];
		"BTC_rally_point" setMarkerText "";
		BTC_rally_point_deployed = nil;publicVariable "BTC_rally_point_deployed";
	};
};
BTC_move_to_rally_point =
{
	closeDialog 0;
	titleText ["Moving to Rally Point", "BLACK OUT"];
	sleep 3;
	titleText ["Moving to Rally Point", "BLACK FADED"];
	sleep 2;
	titleText ["", "BLACK IN"];
	_pos = getPosATL BTC_rally_point;
	player setpos _pos;
};
BTC_m_c_menu =
{
	//Check area libera
	if (count (nearestObjects [getpos BTC_m_c_pos,["All"],5]) > 1) exitWith {hint "Clear the area before create another object!"};
	disableSerialization;
	closeDialog 0;
	_r_dlg = createDialog "BTC_construction_dialog";
	waitUntil {dialog};
	call BTC_m_c_load;
	//_class = lbData [72, 1];_selected = _class;
	_class = lbText [72,lbCurSel 72];_selected = _class;
	_new = _class createVehicleLocal [getpos BTC_m_c_pos select 0,getpos BTC_m_c_pos select 1,0];
	while {dialog} do
	{
		//if (_class != lbData [72, 1]) then
		if (_class != lbText [72,lbCurSel 72]) then
		{
			deleteVehicle _new; sleep 0.1;
			_class = lbText [72,lbCurSel 72];_selected = _class;
			_new = _class createVehicleLocal [getpos BTC_m_c_pos select 0,getpos BTC_m_c_pos select 1,0];
			_new setPos [getpos BTC_m_c_pos select 0,getpos BTC_m_c_pos select 1,0];
		};
		sleep 0.1;
	};
	deleteVehicle _new;
};
BTC_m_c_load = 
{
	lbClear 71;
	_main_class = BTC_construction_array select 0;
	_sub_class  = BTC_construction_array select 1;
	for "_i" from 0 to ((count _main_class) - 1) do
	{
		_lb = lbAdd [71,(_main_class select _i)];if (_i == 0) then {lbSetCurSel [71,_lb];};
	};
	_category = _sub_class select 0;
	lbClear 72;
	for "_i" from 0 to ((count _category) - 1) do
	{
		private ["_class","_display"];
		_class = (_category select _i);
		//_display = getText (configFile >> "cfgVehicles" >> _class >> "displayName");
		//_lb = lbAdd [72,_display];
		//lbSetData [72, _i, _class];
		_lb = lbAdd [72,_class];
		if (_i == 0) then {lbSetCurSel [72,_lb];};
	};	
	true
};
BTC_m_c_apply = 
{
	//_class = lbData [72, 1];
	_class = lbText [72,lbCurSel 72];
	closeDialog 0;sleep 0.2;
	_new = _class createVehicle [getpos BTC_m_c_pos select 0,getpos BTC_m_c_pos select 1,0.5];
	_new setPos [getpos BTC_m_c_pos select 0,getpos BTC_m_c_pos select 1,0];
};
BTC_m_c_change_target = 
{
	_var = lbText [71,lbCurSel 71];
	_main_class = BTC_construction_array select 0;
	_sub_class  = BTC_construction_array select 1;
	_id = _main_class find _var;
	_category = _sub_class select _id;
	lbClear 72;
	for "_i" from 0 to ((count _category) - 1) do
	{
		private ["_class","_display"];
		_class = (_category select _i);
		//_display = getText (configFile >> "cfgVehicles" >> _class >> "displayName");
		//_lb = lbAdd [72,_display];
		_lb = lbAdd [72,_class];
		//lbSetData [_lb, _i, _class];
		if (_i == 0) then {lbSetCurSel [72,_lb];};
	};
};
BTC_r_create_dialog_mobile =
{
	if (BTC_active_lifes != 1 || BTC_lifes != 0) then 
	{
		player allowdamage false;
		deTach player;
		player attachTo [BTC_r_base_spawn,[0,0,6000]];
		//player setpos [0,0,6000];
		player setVelocity [0,0,0];
		BTC_r_camera = "camera" camCreate (position BTC_r_base_spawn);
		BTC_r_camera camSetTarget BTC_r_base_spawn;
		BTC_r_camera cameraEffect ["internal", "BACK"];
		BTC_r_camera camSetPos (BTC_r_base_spawn modelToWorld [-15,-15,15]);
		BTC_r_camera camCommit 0;
		BTC_r_chosen = false;
		BTC_r_list = [];
		BTC_r_mobile_selected = objNull;
		titleText ["", "BLACK IN"];
		sleep 0.5;
		disableSerialization;
		closeDialog 0;
		_r_dlg = createDialog "BTC_move_to_mobile_dialog";
		sleep 0.5;
		titleText ["", "PLAIN"];
		waitUntil {dialog};
		player enableSimulation false;
		call BTC_r_load;
		while {!BTC_r_chosen} do
		{
			if (!dialog && !BTC_r_chosen) then {_r_dlg = createDialog "BTC_move_to_mobile_dialog";sleep 0.5;};
			player setpos [0,0,6000];
			//player setVelocity [0,0,0];
			call BTC_r_load;
			if (count BTC_r_list == 0) then {titleText ["NO SPAWN POINTS FOUND", "PLAIN"];};
			sleep 1;
		};
		player allowdamage true;
		closeDialog 0;
	};
};
//Dialog
BTC_r_get_list =
{
	private ["_leader"];
	_list_str = ["BASE"];
	_list_name = [BTC_r_base_spawn];
	_side = "";_array = [];
	switch (true) do
	{
		case (BTC_side == west) : {_side = "BTC_mobile_west";_array = BTC_vehs_mobile_west_str;};
		case (BTC_side == east) : {_side = "BTC_mobile_east";_array = BTC_vehs_mobile_east_str;};
		case (BTC_side == guer) : {_side = "BTC_mobile_guer";_array = BTC_vehs_mobile_guer_str;};
		case (BTC_side == civ) : {_side = "BTC_mobile_civ";_array = BTC_vehs_mobile_civ_str;};
	};
	{
		_var = _x;
		{
			if (!isNil {_x getVariable _side}) then
			{
				if ((_x getvariable _side) == _var) then {_list_name = _list_name + [_x];_list_str = _list_str + [(_x getvariable _side)];};
			};
		} foreach (vehicles + (nearestObjects [getMarkerPos "respawn_west", ["FlagCarrier"], 555555]));
	} foreach _array;
	_list = [_list_str,_list_name];
	_list
};
BTC_r_load = 
{
	_list = call BTC_r_get_list;
	_list_name = _list select 0;
	_list_units = _list select 1;
	_n = 0;_side = "";
	switch (true) do
	{
		case (BTC_side == west) : {_side = "BTC_mobile_west";_array = BTC_vehs_mobile_west_str;};
		case (BTC_side == east) : {_side = "BTC_mobile_east";_array = BTC_vehs_mobile_east_str;};
		case (BTC_side == guer) : {_side = "BTC_mobile_guer";_array = BTC_vehs_mobile_guer_str;};
		case (BTC_side == civ) : {_side = "BTC_mobile_civ";_array = BTC_vehs_mobile_civ_str;};
	};
	if (!isNull BTC_r_mobile_selected) then {if ((_list_name find (BTC_r_mobile_selected getVariable _side)) == -1 && (_list_name find (name BTC_r_mobile_selected)) == -1) then {BTC_r_mobile_selected = _list_units select 0;};};
	if (count _list_name != count BTC_r_list) then 
	{
		lbClear 119;
		{
			_lb = lbAdd [119,_x];
			if (!isNull BTC_r_mobile_selected) then {if ((BTC_r_mobile_selected getVariable _side) == _x || name BTC_r_mobile_selected == _x) then {lbSetCurSel [119,_lb];};};
			if (isNull BTC_r_mobile_selected) then {lbSetCurSel [119,_lb];_n = _list_name find _x;BTC_r_mobile_selected = _list_units select _n;};
		} foreach _list_name;BTC_r_list = _list_name;
	} else {};
	true
};
BTC_r_apply = 
{
	BTC_r_chosen = true;
	closeDialog 0;
	titleText ["", "BLACK OUT"];
	sleep 0.5;
	titleText ["", "BLACK FADED"];
	player cameraEffect ["terminate","back"];
	camDestroy BTC_r_camera;
	if (!isNull BTC_r_mobile_selected) then 
	{
		player attachTo [BTC_r_mobile_selected,[0,0,-3]];sleep 0.1;deTach player;player setVelocity [0,0,0];player playMoveNow "amovpercmstpsraswrfldnon";
	}
	else
	{
		player setPos getMarkerPos BTC_respawn_marker;
	};
	player enableSimulation true;
	titleText ["", "BLACK IN"];sleep 1;titleText ["", "PLAIN"];
};
BTC_r_change_target = 
{
	_var = lbText [119,lbCurSel 119];
	_target = objNull;_side = "";
	if (_var == "BASE") then {_target = BTC_r_base_spawn;};
	switch (true) do
	{
		case (BTC_side == west) : {_side = "BTC_mobile_west";_array = BTC_vehs_mobile_west_str;};
		case (BTC_side == east) : {_side = "BTC_mobile_east";_array = BTC_vehs_mobile_east_str;};
		case (BTC_side == guer) : {_side = "BTC_mobile_guer";_array = BTC_vehs_mobile_guer_str;};
		case (BTC_side == civ) : {_side = "BTC_mobile_civ";_array = BTC_vehs_mobile_civ_str;};
	};
	{
		if (!isNil {_x getVariable "BTC_mobile_west"}) then
		{
			if ((_x getvariable _side) == _var) then {_target = _x;};
		};
	} foreach (vehicles + (nearestObjects [getMarkerPos "respawn_west",["FlagCarrier"], 555555]));
	//if (!isNull _target) then {BTC_r_mobile_selected = _target;};
	//if (isNull _target) then {BTC_r_mobile_selected = player;};
	BTC_r_mobile_selected = _target;
	BTC_r_camera camSetTarget BTC_r_mobile_selected;
	BTC_r_camera cameraEffect ["internal", "BACK"];
	BTC_r_camera camSetPos (BTC_r_mobile_selected modelToWorld [-15,-15,15]);
	BTC_r_camera camCommit 0;
};
BTC_tracking_sys =
{
	_groups = [];
	{
		if (side _x == BTC_player_side) then
		{
			_groups = _groups + [_x];
		};
	} foreach allGroups;
	_markers = [];
	{
		private ["_type_marker","_unit"];
		_unit = objNull;
		{
			if (isNull _unit && !(captive _x)) then {_unit = _x;};
		} foreach units _x;
		if (!isNil {_x getVariable "BTC_track_sys_false"}) then {_unit = objNull;};
		if (!isNull _unit) then
		{
			_marker = createmarkerLocal [format ["%1", _unit], position _unit];
			_markers = _markers + [format ["%1", _unit]];
			switch (true) do
			{
				case (vehicle _unit isKindOf "Man" || vehicle _unit isKindOf "Static") : {_type_marker = "b_inf";};
				case (vehicle _unit isKindOf "Car" || vehicle _unit isKindOf "Truck" || vehicle _unit isKindOf "Wheeled_APC") : {_type_marker = "b_mech_inf";};
				case (vehicle _unit isKindOf "Tank") : {_type_marker = "b_armor";};
				case (vehicle _unit isKindOf "Helicopter"):  {_type_marker = "b_air";};
				case (vehicle _unit isKindOf "Plane"):  {_type_marker = "b_plane";};
			};
			format ["%1", _unit] setmarkertypelocal _type_marker;
			format ["%1", _unit] setMarkerTextLocal format ["%1", groupID _x];
			format ["%1", _unit] setMarkerSizeLocal [0.6, 0.6];
		};
	} foreach _groups;
	sleep 5;
	{deleteMarkerLocal _x;} foreach _markers;
	_sys = [] spawn BTC_tracking_sys;
};
BTC_marker_debug =
{
	_units = allunits;
	if !(BTC_marker_debug_cond) exitWith {};
	_color = "";
	{
		if (Alive _x) then
		{
			_marker = createmarkerLocal [format ["%1", _x], position _x];
			format ["%1", _x] setmarkertypelocal "mil_Dot";
			format ["%1", _x] setMarkerTextLocal format ["%1", typeOf _x];//typeOf
			if (side _x == west) then {_color = "ColorBlue"} else {_color = "ColorRed"};
			format ["%1", _x] setmarkerColorlocal _color;
			format ["%1", _x] setMarkerSizeLocal [0.7, 0.7];
			if (leader group _x == _x && !isNil {group _x getVariable "BTC_patrols_ID"}) then {format ["P ID %1", _x] setMarkerTextLocal format ["%1", group _x getVariable "BTC_patrols_ID"];};
		}
		else
		{
			format ["%1", _x] setMarkerPosLocal [0,0];
			format ["%1", _x] setMarkerTextLocal "";
			deleteMarker format ["%1", _x];
		};
	} foreach _units;
	player sideChat format ["UNITS:%1 - GROUPS:%2", count allunits, count allgroups];
	sleep 1;
	{deleteMarker format ["%1", _x]} foreach _units;
	_marker = [] spawn BTC_marker_debug;
};